﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using JX.Core;
using JX.Core.Entity;
using JX.Infrastructure.Field;

namespace JX.Core
{
	/// <summary>
	/// 数据库表：Models 的仓储接口.
	/// </summary>
	public partial interface IModelsRepositoryDapper : IRepositoryDapper<ModelsEntity>
	{
		#region 得到节点绑定的模型列表：表：Model,NodesModelTemplate
		/// <summary>
		/// 得到节点绑定的模型列表
		/// </summary>
		/// <param name="nodeId"></param>
		/// <param name="enable">是否启用（true：启用；false：禁用；）</param>
		/// <param name="modelTyp">模型类型</param>
		/// <param name="writeAndRead"></param>
		/// <returns></returns>
		DataTable GetModelListByNodeId(int nodeId, bool enable = true, ModelType modelTyp = ModelType.Content, WriteAndReadEnum writeAndRead = WriteAndReadEnum.None);
		#endregion

		#region 更新字段
		/// <summary>
		/// 更新字段
		/// </summary>
		/// <param name="modelType"></param>
		/// <param name="fieldList"></param>
		/// <returns></returns>
		bool UpdateField(ModelType modelType, string fieldList);
		/// <summary>
		/// 更新字段
		/// </summary>
		/// <param name="modelId"></param>
		/// <param name="fieldList"></param>
		/// <returns></returns>
		bool UpdateField(int modelId, string fieldList);
		#endregion

		#region 模型扩展表
		/// <summary>
		/// 添加模型字段列到模型扩展表
		/// </summary>
		/// <param name="fieldInfo"></param>
		/// <param name="tableName"></param>
		void AddFieldToTable(FieldInfo fieldInfo, string tableName);
		/// <summary>
		/// 从指定的模型扩展表中，移除指定字段列
		/// </summary>
		/// <param name="fieldName"></param>
		/// <param name="tableName"></param>
		void DeleteTableField(string fieldName, string tableName);
		/// <summary>
		/// 从指定模型扩展表中，移除指定行政区域字段列
		/// </summary>
		/// <param name="fieldName"></param>
		/// <param name="tableName"></param>
		void DeleteTableRegionField(string fieldName, string tableName);
		/// <summary>
		/// 从指定模型扩展表中，移除指定行政区域(5级)字段列
		/// </summary>
		/// <param name="fieldName"></param>
		/// <param name="tableName"></param>
		void DeleteTableRegionFiveField(string fieldName, string tableName);
		/// <summary>
		/// 删除模型扩展表
		/// </summary>
		/// <param name="modelId"></param>
		/// <returns></returns>
		bool DeleteTable(int modelId);
		/// <summary>
		/// 更新模型扩展表中的字段列
		/// </summary>
		/// <param name="fieldInfo"></param>
		/// <param name="tableName"></param>
		void UpdateTableField(FieldInfo fieldInfo, string tableName);

		/// <summary>
		/// 在指定表中查找指定字段的值列表，如果表名为“CommonInfo”，需要指定modelId
		/// </summary>
		/// <param name="tableName">模型表名</param>
		/// <param name="fieldName">模型字段名</param>
		/// <param name="modelId">模型ID</param>
		/// <param name="writeAndRead"></param>
		/// <returns></returns>
		IList<string> GetLookupField(string tableName, string fieldName, int modelId, WriteAndReadEnum writeAndRead = WriteAndReadEnum.None);
		#endregion
	}
}